package com.hframe.taglib.json;

import com.google.gson.JsonParser;

import javax.servlet.jsp.JspException;

public class JsonPrimitiveTag extends JsonBaseTag {
	private static final long serialVersionUID = 1L;

	@Override
	public int doStartTag() throws JspException {
		out = true;
		try {
			if (this.json != null)
				this.setObJson(new JsonParser().parse(this.json));
			else {
				JsonBaseTag parent = getParent();
				if (parent != null)
					this.setObJson(parent.getObJson());
			}
			if (null != this.obJson && !this.obJson.isJsonPrimitive()) {
				this.obJson = null;
			}
			GetJson();
			outJson();
		} catch (Exception e) {
		}
		return super.doStartTag();
	}

	@Override
	protected void GetJson() {
		if (null == this.obJson)
			return;

		if (this.obJson.isJsonPrimitive())
			this.json = this.obJson.getAsString();
	}

	@Override
	public int doEndTag() throws JspException {
		return super.doEndTag();
	}
}
